package cn.tedu.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

//测试 代表客户端
public class Client {
    public static void main(String[] args) throws IOException {
        //1.连接服务器--服务器的ip和端口号
        Socket socket=new Socket( "176.198.9.8",8000);
        System.out.println("客户端与服务器连接成功..");

        //2.给服务写出
        OutputStream out=socket.getOutputStream();
        out.write("hello".getBytes());
        out.flush();//只刷出去数据不关流
        //3.读取数据--in
        InputStream in= socket.getInputStream();
        for (int i = 0; i < 5; i++) {
            //问题：rend()默认返回值类型是int，想变成char强转
            char c= (char) in.read();
            System.out.print(c);
        }
    }
}
